package com.example.templateapp.util.http

import android.content.Context
import com.baidu.tts.client.SpeechSynthesizer
import com.baidu.tts.client.TtsMode

object SpeechSynthesizerFactory {
    private val AppId = "20201435"
    private val AppKey = "7p2YHfW5zdPzYKAbUfFry2RF"
    private val AppSecret = "twLXsp7ovpUs3nqtsGDNZyzL9GvqPgdE"
    private var speecher: SpeechSynthesizer? = null

    fun getInstance(context: Context): SpeechSynthesizer {
        if (speecher == null) {
            speecher = init(context.applicationContext)
        }
        return speecher!!
    }

    private fun init(context: Context): SpeechSynthesizer {
        val instance = SpeechSynthesizer.getInstance()

        instance.setContext(context)
        instance.setAppId(AppId)
        instance.setApiKey(AppKey, AppSecret)
        instance.auth(TtsMode.ONLINE)
        instance.setParam(SpeechSynthesizer.PARAM_SPEAKER, "0")
        instance.initTts(TtsMode.ONLINE)

        return instance
    }
}